﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZLCMS.Business;
using ZLCMS.Business.DwzFrame;
using NHibernate;

namespace ZLCMS.Web.SystemManage.Basics.MemberCard
{
    public partial class Add : System.Web.UI.Page
    {
        protected FrameHelper _framePage;

        protected void Page_Load(object sender, EventArgs e)
        {
            _framePage = new FrameHelper(this);
            if (!string.IsNullOrEmpty(Request["ajax"]))
            {
                AddMemberCard();
            }
        }

        protected void AddMemberCard()
        {
            using (ISession session = DotNet.Common.NHibernateUtil.SessionFactoryHelper.CreateSession())
            {
                ZLCMS.Data.Model.MemberCard member = new ZLCMS.Data.Model.MemberCard();
                try
                {
                    member.Id = tb_cardid.Text;
                    member.Username = tb_username.Text;
                    member.Qq = tb_qq.Text;
                    member.Phone = tb_phone.Text;
                    member.Mobile = tb_mobile.Text;
                    member.Company = tb_company.Text;
                    member.Addr = tb_addr.Text;
                    member.Email = tb_email.Text;
                    member.Fax = tb_fax.Text;
                    member.Postcode = tb_postcode.Text;
                    if (!String.IsNullOrEmpty(tb_mpoint.Text))
                    {
                        member.Mpoint = decimal.Parse(tb_mpoint.Text);
                    }
                    if (!String.IsNullOrEmpty(tb_mcash.Text))
                    {
                        member.Mcash = decimal.Parse(tb_mcash.Text);
                    }
                    if (!String.IsNullOrEmpty(tb_mtime.Text))
                    {
                        member.Mtime = decimal.Parse(tb_mtime.Text);
                    }
                    if (!String.IsNullOrEmpty(tb_mdiscount.Text))
                    {
                        member.Mdiscount = decimal.Parse(tb_mdiscount.Text);
                    }
                }
                catch (System.Exception ex)
                {
                    _framePage.Alert(new ReturnCode() { statusCode = 300, message = "输入信息有误-" + ex.Message });
                    return;
                }
                session.Save(member);
                session.Flush();

                _framePage.Alert(new ReturnCode() { statusCode = 200, message = "操作成功!", navTabId = _framePage.NavTabId });
            }
        }
    }
}
